<template>
  <div>
    <el-form
      :inline="true"
      :model="formData"
      size="small"
      class="demo-form-inline"
    >
      <el-form-item prop="title" label="标题">
        <el-input
          v-model="formData.title"
          clearable
          placeholder="标题"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="success" @click="$refs.notice.show()">新增公告</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="tableData">
      <el-table-column prop="title" label="标题" width="180"> </el-table-column>
      <el-table-column prop="content" label="内容" width="400">
      </el-table-column>
      <el-table-column prop="key" label="关键词" width="180"> </el-table-column>
      <el-table-column prop="publisher" label="作者" width="120">
      </el-table-column>
      <el-table-column prop="createTime" label="发布时间" width="180">
      </el-table-column>
      <el-table-column fixed="right" label="操作">
        <template slot-scope="scope">
          <el-button type="success" size="mini" @click="$refs.notice.show(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <v-pagination :formData="formData" @load="getData"></v-pagination>
    <notice-modal ref="notice" @load="getData"></notice-modal>
  </div>
</template>
<script>
import { queryNoticeList } from "@/api/newsManagement/notice";
import pagination from "@/components/pagination";
import noticeModal from "./modules/noticeModal";
export default {
  components: {
    vPagination: pagination,
    noticeModal
  },
  data() {
    return {
      formData: {
        title: "",
        pageNo: 1,
        pageSize: 10,
        total: 0,
      },
      loading: true,
      tableData: [],
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      this.loading = true;
      queryNoticeList(this.formData).then((res) => {
        this.loading = false;
        this.tableData = res.data.resultData.noticeList;
        this.formData.total = res.data.resultData.count;
      });
    },
    onSubmit() {
      this.formData.pageNo = 1;
      this.formData.pageSize = 10;
      this.formData.total = 0;
      this.getData();
    },
  },
};
</script>